package n13_reentrantlock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author fu
 * @date 2022-01-08 17:55
 * 概要：
 *----------------------------------------------------------------------
 |                                                                     |
 |                    测试 Renntrantlock的可重入 方法                    |
 |                                                                    |
 |====================================================================*/
@Slf4j(topic = "c.T1")
public class T1_reentrantlock_可重入 {

    /*
     之前 synchronized 参数对象 关联的 Monitor 是锁
     这里 lock 对象本身就是 锁
     */
    private static ReentrantLock lock =  new ReentrantLock();

    public static void main(String[] args) {

        lock.lock();
        try{
            log.debug("enter main1");
            m1();

        } finally {
            lock.unlock();
        }

    }

    public static void m1(){
        lock.lock();
        try{
            log.debug("enter m1()11111111");
            m2();
        } finally {
            lock.unlock();
        }
    }

    public static void m2(){
        lock.lock();
        try{
            log.debug("enter m2()22222222");
        } finally {
            lock.unlock();
        }
    }

}







